<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>渠道管理 - 规格设置</title>
<?php include($this->c['_homes']['_viewsHome'].'/_global/_head.php');?>
<link rel="stylesheet" type="text/css" href="/style/assets/plugins/bootstrap-datetimepicker/css/datetimepicker.css" />
<link href="/style/assets/css/summernote.css" rel="stylesheet">
<link href="/style/assets/css/summernote-bs3.css" rel="stylesheet">
    <style type="text/css">

        #txt1 {
            width: 99%;
        }

        #div_items {
            position: relative;
            width: 100%;
            height: 200px;
            border: 1px solid #66afe9;
            border-top: 0px;
            overflow: auto;
            display: none;
        }

        .div_item {
            width: 100%;
            height: 20px;
            margin-top: 1px;
            font-size: 13px;
            line-height: 20px;
        }
        .checkbox-inline{
	
        	    padding-left:2px!important;
        	    margin-left:0px!important;
        }
        .form-actions{
	
        	background-color:#fff;
        	border:none;
        }
  .popup{ background-color: rgba(0,0,0,0.5);width: 100%;height: 100%;position: fixed;top: 0;z-index: 9999;display:none;}
    </style>
</head>
<!-- BEGIN BODY -->
<body class="page-header-fixed page-sidebar-fixed">
<!-- BEGIN HEADER -->
<?php include($this->c['_homes']['_viewsHome'].'/_global/head.php');?>
<!-- END HEADER -->
<div class="clearfix"></div>
<!-- BEGIN CONTAINER -->
<div class="page-container" > 
  <!-- BEGIN HORIZONTAL MENU PAGE SIDEBAR1 -->
  <?php include($this->c['_homes']['_viewsHome'].'/_global/menu.php');?>
  <!-- END BEGIN HORIZONTAL MENU PAGE SIDEBAR --> 
  <!-- BEGIN PAGE -->
  <div class="page-content"> 
    <!-- BEGIN PAGE HEADER-->
    <div class="row">
      <div class="col-md-12"> 
        <!-- BEGIN PAGE TITLE & BREADCRUMB-->
        <h3 class="page-title">  规格设置 </h3>
        <ul class="page-breadcrumb breadcrumb">
          <li> <i class="icon-home"></i> <a href="/manage">后台</a> <i class="icon-angle-right"></i> </li>
          <li> 渠道管理 <i class="icon-angle-right"></i> </li>
          <li> <a href="channelgoods">渠道商品</a> <i class="icon-angle-right"></i> </li>
          <li> 规格设置</li>
        </ul>
        <!-- END PAGE TITLE & BREADCRUMB--> 
      </div>
    </div>
    <!-- END PAGE HEADER--> 
    <!-- BEGIN PAGE CONTENT-->
    
    <div class="row">
      <div class="col-md-12"> 
        <!-- BEGIN SAMPLE FORM PORTLET-->
        
          <div class="tabbable tabbable-custom boxless">
            <ul class="nav nav-tabs">
              <li class="active"><a href="#tab_0" data-toggle="tab">基本信息</a></li>
            </ul>
            <div class="tab-content"> 
              <!--Tab0-->
              <div class="tab-pane active" id="tab_0">
                <div class="portlet box blue ">
                  <div class="portlet-title">
                    <div class="caption"> <i class="icon-reorder"></i> 基本信息 </div>
                  </div>
                  <div class="portlet-body form">
                    <div class="form-body">
               
                 <?php
    			  if($this->data[0]){
    				foreach($this->data[0] as $k=>$r){
    					?>	
                      <div class="form-group" >
                         <label class="col-md-1 control-label"><?=$r['name']?></label>
                        <div class="col-md-1" style="width:100%;margin-left:4rem">
                          <div class="checkbox-list">
                           <?php
        					if($this->data[$r['caid']]){
        						foreach($this->data[$r['caid']] as $j=>$s){
        							
        						?>
                            <label class="checkbox-inline">
                          <?=$s['name']?><input  value="<?=$s['caid'];?>" name="spec<?=$r['caid']?>" type="radio" data-name="<?=$s['name']?>" data-id="<?=$r['caid'];?>">
                          </label>
                          <?php }}?>
                          </div>
                        </div>
                      </div>
                      <?php }}?>
                       <div class="form-actions fluid" style="padding-left:300px;">
                      <div class="col-md-offset-1 col-md-9">
                        <button type="botton" onClick="spec_sub();" class="btn blue">添加</button>
                      </div>
                    </div>
                      <form class="form-horizontal" id="forms">
                         <input type="hidden" name="act" value="goods_spec_set" />
                          <input type="hidden" name="goods_id" value="<?=$this->goods_id;?>" />
                         <input type="hidden" name="page" value="<?=$_GET['page'];?>">
                         <input type="hidden" name="ref" value="<?=$_SERVER['HTTP_REFERER'];?>">
                       <div class="row">
                      <div class="col-md-12"> 
                        <!-- BEGIN SAMPLE TABLE PORTLET-->
                        <div class="portlet box blue">
                          <div class="portlet-title">
                            <div class="caption"><i class="icon-list"></i>列表(<?=$this->data['count'];?>)</div>
                            <div class="actions">
                            </div>
                          </div>
                          <div class="portlet-body">
                            <div class="table-scrollable">
                             <table class="table table-striped table-bordered table-hover dataTable">
                                <thead>
                                  <tr>                    
                                    <th>规格属性</th>
                                      <th>国际码</th>
                                    <th>会员价</th>
                                    <th>库存</th>
                                      <th>操作</th>
                                  </tr>
                                </thead>
                                <tbody id="content">
                                 <?php
                                   if($this->goods_spec['data']){
                                     foreach($this->goods_spec['data'] as $k=>$r){   
                                 
                                 ?>
                                 <tr>
                                   <td><?=$r['spec_name']?><input type="hidden" class="spec_ids" value="<?=$r['spec_id']?>"></td>
                                     <td data-val="<?=$r['goods_sn']?>" data-type="2" data-id="<?=$r['stock_id']?>" onClick="spec_set(this)"><?=$r['goods_sn']?></td>
                                   <td data-val="<?=$r['goods_price']?>" data-type="0" data-id="<?=$r['stock_id']?>" onClick="spec_set(this)"><?=$r['goods_price']?></td>
                                   <td data-val="<?=$r['goods_number']?>" data-type="1" data-id="<?=$r['stock_id']?>" onClick="spec_set(this)"><?=$r['goods_number']?></td>
                                   <td style="cursor:pointer" data-id="<?=$r['stock_id']?>" onClick="spec_stat(this)"><?=$r['stat']==1?"<span class='label label-danger'>禁用</span>":"<span class='label label-success'>启用</span>";?></td>
                                 </tr>
                                  
                               <?php 
                                     }
                                  
                                   }
                                 ?>
                                   
                                   
                                </tbody>
                               <?php if($this->goods_spec['stock_total']){?>
                                <tr>
                                    <td colspan="3">库存合计：</td>
                                    <td id="stock-total"><?=$this->goods_spec['stock_total']?></td>
                                    <td ></td>
                                    </tr>
                                    <?php }?>
                              </table>
                            </div>
                          </div>
                        </div>
                         <div class="form-actions fluid" style="padding-left:300px;">
                      <div class="col-md-offset-1 col-md-9">
                        <input type="botton" onClick="confirm_sub();" class="btn blue" value="添加">
                      </div>
                    </div>
                        <!-- END SAMPLE TABLE PORTLET--> 
                      </div>
                    </div>
                    </form>
                    
                  </div>
                </div>
              </div>              
            </div>
          </div>
          
          
        
        <!-- END SAMPLE FORM PORTLET--> 
      </div>
    </div>
    <!-- END PAGE CONTENT--> 
  </div>
  <!-- END PAGE --> 
</div>
<div class="popup" id="myModal">
    <div class="modal-dialog" style="margin-top:150px;">
        <div class="modal-content">
            <div class="modal-header">
                <h4 class="modal-title text-center" id="_title">
                    会员价
                </h4>
            </div>
            <input class="input-block-level text-center" type="text" name="keyword" id="_keyword" placeholder="" style="margin: 20px auto;display: block;">
            <input type="hidden" name="type"  value="0" id="_type"/>
            <input type="hidden" name="stock_id"  value="" id="_stock_id"/>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal" id="_close">关闭</button>
                <button type="button" class="btn btn-primary text-right" id="stock_sub">更改</button>
            </div>
        </div>
    </div>
</div>
<!-- END CONTAINER -->
<?php include($this->c['_homes']['_viewsHome'].'/_global/_footer.php');?>
<script type="text/javascript" src="/style/assets/plugins/ckeditor/ckeditor.js"></script> 
<script>
jQuery(document).ready(function() {    
	   App.init();
	
})

function spec_stat(obj)
{
    var sid = $(obj).attr('data-id');

    if(sid >0){

        $.ajax({
            type: 'post',
            url: 'ajax',
            data: {
                "act":"stock_stat",
                "stock_id":sid,
                "mr": Math.random()

            }
            ,
            dataType: 'json',
            success: function(data) {
                window.location.reload();
            }
        });
    }

}

function spec_sub(){
	var spec_id=""; 
	var  spec_name ="";
	$("input[type='radio']").each(function(i){
		
		   if($(this).is(':checked')){
			      if(spec_id ==""){
			    	  spec_id = $(this).val();
			    	  spec_name  = $(this).attr("data-name");
				     }else{
				    	  spec_id = spec_id+","+$(this).val();
				    	  spec_name  = spec_name+";"+$(this).attr("data-name");
					   }
				  
			   }
		   
		});
	
	if(spec_id !="" && spec_name !=""){
          var stat=true;
		$(".spec_ids").each(function(i){
			      
		         if(spec_id == $(this).val()){
		        	   stat = false;
			         }
			   
			});

		if(stat){
          //alert(spec_id+spec_name)
    		var html="";
    		html +='<tr class="spec"><td >'+spec_name+'<input type="hidden" name="spec_ids[]" class="spec_ids" value="'+spec_id+'"/><input type="hidden" name="spec_names[]"  value="'+spec_name+'"/></td>';
    		html +='<td><input type="text" class="goods_sn"  name="goods_sn[]"/></td><td><input type="text" class="goods_price"  name="goods_price[]"/></td><td><input type="text" name="goods_number[]" class="goods_number" /></td>';
             html += '<td></td></tr>';
            $("#content").append(html);
		}else{
            swal('已添加规格')

		}

	 }
}

$("#_close").click(function(){
	$(".popup").hide();
	
})
//库存修改
function spec_set(obj){
	
    var stock_id = $(obj).attr('data-id');
    var type = $(obj).attr('data-type');
    var v = $(obj).attr('data-val');
	$(".popup").show();
	if(type ==1){
        $("#_title").html("库存");
    }else if(type ==2){
        $("#_title").html("国际码");

    }

	$("#_keyword").val(v);
	$("#_type").val(type);
	$("#_stock_id").val(stock_id);
	//$("#myModal").addClass('myModal');
	
}
//库存提交
$("#stock_sub").click(function(){
	   var stock_id = $("#_stock_id").val();
	    var type = $("#_type").val();
	    if(type !=2){
            var v = parseFloat($("#_keyword").val());

        }else{
            var v = $("#_keyword").val();

        }

        if(stock_id >0){

            $.ajax({
                type: 'post',
                url: 'ajax',
                data: {
                	"act":"stock_edit",
                    "stock_id":stock_id,
                    "type":type,
                    "keyword":v,
                	"mr": Math.random()
                    
                    }
                ,
                dataType: 'json',
                success: function(data) {
                    if (data != "") {
                        if (data.code == 200) {
                            swal(data.msg, false, "success");
                            setTimeout(function(){
                            	window.location.reload();
                            },1500);
                        } else {
                       	    swal(data.msg,false,"error");
                        }
                    }
                }
            });
        }else{
             swal("输入值不能小于0");
          }
	
})
//规格提交
function confirm_sub(){
  
	var done = true;
	
   if($("#content .spec").size()<=0){
	      swal('请添加规格属性')
	      done  =false;
	   }

   if(done){
	  
     	$("#content .spec").each(function(i){
    	      
            if($(this).find('.spec_ids').val() ==""){
            	 done  =false;
           	     swal('规格属性不能为空');
    	       }

         /*   if($(this).find('.goods_sn').val() ==""){
                done  =false;
                swal('国际码不能为空');
            }*/
            if($(this).find('.goods_price').val() ==""){
            	 done  =false;
         	     swal('会员价不能为空');
  	       }
            if($(this).find('.goods_number').val() ==""){
            	 done  =false;
         	     swal('库存不能为空');
  	       }
    	   
    	});
   }
  
   if(!done){
	  
       return false;
   }
    $.ajax({
        type: 'post',
        url: 'ajax',
        data: $("#forms").serialize() + "&mr=" + Math.random(),
        dataType: 'json',
        success: function(data) {
            if (data != "") {
                if (data.code == 200) {
                    swal(data.msg, false, "success");
                    setTimeout(function(){
                    	window.location.reload();
                    },1500);
                } else {
               	    swal(data.msg,false,"error");
                }
            }
        }
    });
	
}
</script> 
<!-- END JAVASCRIPTS -->
</body>
<!-- END BODY -->
</html>